package com.kingdee.pda.ui.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import com.kingdee.pda.R;
import com.kingdee.pda.callback.OnConfirmClickCallback;
import com.kingdee.pda.util.KeyboardUtils;

/**
 * 备注编辑
 * Created by zhanlg
 * DATE 2020/1/3
 * TIME 11:27
 */

public class NoteEditDialog extends BaseAlertDialog<NoteEditDialog> implements View.OnClickListener {


    private Context mContext;
    private String mNote;
    private EditText mEtNote;
    private OnConfirmClickCallback<String> mCallback;


    public NoteEditDialog(Context context, String note, OnConfirmClickCallback<String> callback) {
        super(context);
        this.mContext = context;
        this.mNote = note;
        this.mCallback = callback;
    }

    @Override
    public View onCreateView() {
        setCanceledOnTouchOutside(false);
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_note_edit, null);
        mLlContainer.addView(view);
        initView(view);
        return mLlContainer;
    }

    private void initView(View view) {
        mEtNote = view.findViewById(R.id.et_note);
        view.findViewById(R.id.btn_confirm).setOnClickListener(this);
        view.findViewById(R.id.iv_close).setOnClickListener(this);

        mEtNote.setText(mNote);
        mEtNote.setSelection(mNote.length());
        KeyboardUtils.openSoftKeybord(mEtNote, mContext);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_confirm:
                if (mCallback != null) {
                    mCallback.onConfirmClick(mEtNote.getText().toString().trim());
                }
                dismiss();
                break;
            case R.id.iv_close:
                KeyboardUtils.closeSoftKeybord(mEtNote, mContext);
                dismiss();
                break;
        }
    }
}
